/*
 * TODO
 */
package com.xtrip.net.response;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.xtrip.adm.model.City;
import com.xtrip.common.BusinessConstant;

/**
 * @project xtrip
 * @author shiming.yao
 * @time 2013-4-3
 */
public class ResponseDataParser {
	public static Object parse(String type,int provider,String src){
		if(type.equals(BusinessConstant.TYPE_HOTEL))return parseHotel(provider,src);
		else if(type.equals(BusinessConstant.TYPE_PLANE))return parsePlane(provider,src);
		return null;
	}
	private static Object parseHotel(int provider,String src){
		Object result = null;
		switch (provider) {
			case BusinessConstant.PROVIDER_HOTEL_ELONG:
				result = parseFromElong(src);
				break;
			case BusinessConstant.PROVIDER_HOTEL_CTRIP:
				result = parseFromCtrip(src);
				break;
			case BusinessConstant.PROVIDER_HOTEL_17U:
				result = parseFrom17U(src);
				break;
			case BusinessConstant.PROVIDER_HOTEL_ZHUNA:
				result = parseFromZhuna(src);
				break;
		}
		return result;
	}
	private static String parseFromElong(String src){
		return null;
	}
	private static String parseFromCtrip(String src){
		return null;
	}
	private static String parseFrom17U(String src){
		return null;
	}
	private static Object parseFromZhuna(String src){
		JSONObject jo = JSONObject.fromObject(src);
		JSONObject retHeader = jo.getJSONObject("retHeader");
		JSONArray reqdata = jo.getJSONArray("reqdata");
		String retCod = (String) jo.get("retcode");
		System.out.println("住哪返回记录数:"+reqdata.size());
		System.out.println("住哪retCod:"+jo.get("retcode")+",totalput:"+retHeader.getString("totalput"));
		List<City> list = new ArrayList<City>();
		if(retCod.equals("city")){
			for(int i=0;i<reqdata.size();i++){
				JSONObject o=reqdata.getJSONObject(i);
				City city = new City();
				city.setName(o.getString("cName"));
				city.setProId(o.getString("pName"));
				city.setZhunaCid(o.getString("cid"));
				city.setZhunaHCnt(Integer.parseInt(o.getString("hotelNum")));
				list.add(city);
			}
		}
		
		return list;
	}
	private static String parsePlane(int provider,String src){
		return null;
	}
}
